package com.dal.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.dal.db.cache.TempRewardCache;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static com.dal.db.StaticResource.TempRewardResource.*;
import static com.dal.db.StaticResource.TempRewardResource.*;
/**
 * 临时奖励
 */
public class TempReward extends BasePojo<TempReward> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* 手机号
	*/
	private String phoneNumber;
	
	/**
	* 道具ID
	*/
	private int itemId;
	
	/**
	* 道具数量
	*/
	private int itemCount;
	
	/**
	* 是否领取
	*/
	private boolean receive;
	
	/**
	* 创建时间
	*/
	private java.util.Date createDate;
	
	/**
	* 修改时间
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 领取时间
	*/
	private java.util.Date receiveDate;
	
	
	@Deprecated
	public static TempReward builder() {
		TempReward tempReward = new TempReward();
		return tempReward;
	}
	
	@Deprecated
	public TempReward() {
		super();
	}
	
	public TempReward(String phoneNumber, int itemId, int itemCount, boolean receive, java.util.Date receiveDate) {
		super();
		this.phoneNumber = phoneNumber;
		this.itemId = itemId;
		this.itemCount = itemCount;
		this.receive = receive;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.receiveDate = receiveDate;
	}
	
	/**
	 * 手机号
	 */
	public String getPhoneNumber() {return phoneNumber;}
	
	/**
	 * 手机号
	 */
	public TempReward setPhoneNumber(String phoneNumber) {this.phoneNumber = phoneNumber;return this;}
	
	/**
	 * 道具ID
	 */
	public int getItemId() {return itemId;}
	
	/**
	 * 道具ID
	 */
	public TempReward setItemId(int itemId) {this.itemId = itemId;return this;}
	
	/**
	 * 道具数量
	 */
	public int getItemCount() {return itemCount;}
	
	/**
	 * 道具数量
	 */
	public TempReward setItemCount(int itemCount) {this.itemCount = itemCount;return this;}
	
	/**
	 * 是否领取
	 */
	public boolean isReceive() {return receive;}
	
	/**
	 * 是否领取
	 */
	public TempReward setReceive(boolean receive) {this.receive = receive;return this;}
	
	/**
	 * 创建时间
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * 创建时间
	 */
	protected TempReward setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * 修改时间
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * 修改时间
	 */
	protected TempReward setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 领取时间
	 */
	public java.util.Date getReceiveDate() {return receiveDate;}
	
	/**
	 * 领取时间
	 */
	public TempReward setReceiveDate(java.util.Date receiveDate) {this.receiveDate = receiveDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.phoneNumber;
        values[1] = this.itemId;
        values[2] = this.itemCount;
        values[3] = this.receive;
        values[4] = this.createDate;
        values[5] = this.modifiedDate;
        values[6] = this.receiveDate;
        return values;
	}
	
	public TempReward deepCopy(){
		TempReward tempReward = null;
		try {
			tempReward = (TempReward) super.clone();
		    tempReward.setCreateDate(ToolCopy.copyObject(this.createDate));
		    tempReward.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    tempReward.setReceiveDate(ToolCopy.copyObject(this.receiveDate));
		    // 克隆索引
		    tempReward.indexValues = ArrayUtils.clone(indexValues);
			return tempReward;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return tempReward;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.phoneNumber);
        map.put(keys[1], this.itemId);
        map.put(keys[2], this.itemCount);
        map.put(keys[3], this.receive);
        map.put(keys[4], this.createDate);
        map.put(keys[5], this.modifiedDate);
        map.put(keys[6], this.receiveDate);
        return map;
    }
    
    protected TempReward createForMap(Object[] keys,Map map){
   		this.phoneNumber = (String)map.get(keys[0]);
   		this.itemId = (int)map.get(keys[1]);
   		this.itemCount = (int)map.get(keys[2]);
   		this.receive = (boolean)map.get(keys[3]);
   		this.createDate = (java.util.Date)map.get(keys[4]);
   		this.modifiedDate = (java.util.Date)map.get(keys[5]);
   		this.receiveDate = (java.util.Date)map.get(keys[6]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.phoneNumber);
        obj.put(keys[1], this.itemId);
        obj.put(keys[2], this.itemCount);
        obj.put(keys[3], this.receive);
        obj.put(keys[4], this.createDate);
        obj.put(keys[5], this.modifiedDate);
        obj.put(keys[6], this.receiveDate);
        return obj;
    }
    
    protected TempReward createForJSONObject(Object[] keys,JSONObject obj){
	    this.phoneNumber = obj.getString(keys[0]);
	    this.itemId = obj.getIntValue(keys[1]);
	    this.itemCount = obj.getIntValue(keys[2]);
	    this.receive = obj.getBooleanValue(keys[3]);
	    this.createDate = obj.getDate(keys[4]);
	    this.modifiedDate = obj.getDate(keys[5]);
	    this.receiveDate = obj.getDate(keys[6]);
        return this;
    }
    
    
    public TempReward createForResultSet(ResultSet rs) throws SQLException{
	    this.phoneNumber = rs.getString(SOURCE_COLUMN_NAMES[0]);
	    this.itemId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.itemCount = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.receive = rs.getBoolean(SOURCE_COLUMN_NAMES[3]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.receiveDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeString(this.phoneNumber);
	    byteBuf.writeInt(this.itemId);
	    byteBuf.writeInt(this.itemCount);
	    byteBuf.writeBoolean(this.receive);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeDate(this.receiveDate);
    }
	
	protected TempReward readBytes(IByteBuff byteBuf){
	    this.phoneNumber = byteBuf.readString(null);
	    this.itemId = byteBuf.readInt(null);
	    this.itemCount = byteBuf.readInt(null);
	    this.receive = byteBuf.readBoolean(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.receiveDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public TempReward insert(){
    	return TempRewardCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public TempReward update(){
    	return TempRewardCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return TempRewardCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public TempReward insertAndFlush(){
    	return TempRewardCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public TempReward updateAndFlush(){
    	return TempRewardCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return TempRewardCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public TempReward syncIndexValues(){
		indexValues[0] = SK_Plus.b(getPhoneNumber()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getPhoneNumber();
	}
	
	protected void setPrimaryKey(Object key){
		setPhoneNumber((String)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}